<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>

<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch" data-options="{searchDatagrid:$.CurrentNavtab.find('#user_table')}">
        <fieldset>
            <legend style="font-weight:normal;">条件搜索：</legend>
            <div style="margin:0; padding:1px 5px 5px;">
                <label class="row-label">用户名：</label>
                <input type="text" name="userModel.userName" class="form-control" data-width="130">
                    
                <label class="row-label">真实姓名：</label>
                <input type="text" name="userModel.name" class="form-control" size="8">

                <label class="row-label">&nbsp;&nbsp;身份证：</label>
                <input type="text" name="userModel.idNumber" class="form-control" size="18">
                    
                <div class="btn-group">
                    <button type="submit" class="btn-green" data-icon="search">搜索</button>
                    <button type="reset" class="btn-orange" data-icon="times">重置</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table id="user_table" class="table table-bordered">
    </table>
    <script type="text/javascript">
        var user_table;
        $(function () {
            user_table = $('#user_table').datagrid({
                height: '100%',
                width: '100%',
                fullGrid: true,
                showToolbar: true,
                filterThead: false,
                delPK: 'id',
                dataUrl: '/admin/user/allUser?_=' + new Date().getTime(),
                local: "remote",
                inlineEditMult: false,
                saveAll: false,
                contextMenuB: true,
                addLocation: 'last',
                toolbarItem: 'del,|,edit,|,save,|,cancel,|,refresh,|,import',
                toolbarCustom: function () {
                    return '<button type="button" class="btn btn-green" onclick="userListExport();" data-icon="sign-out"><i class="fa fa-sign-out"></i> 导出</button>';
                },
                postData: {
                    totalProfit: "user_profit",
                    totalBalance: "user_balance",
                    totalFreezing: "user_freezing"
                },
                delConfirm: true,
                columns: [
                    {
                        render: userListShowUser,
                        label: '用户名',
                        align: 'center'
                    }, {
                        name: 'name',
                        label: '姓名',
                        align: 'center',
                        rule: 'chinese'
                    }, {
                        name: 'sex',
                        label: '性别',
                        align: 'center',
                        type: 'select',
                        items: [{0: '女'}, {1: '男'}],
                        render: $.datagrid.renderItem
                    }, {
                        name: 'idNumber',
                        label: '身份证号码',
                        align: 'center',
                        rule: 'IDcard'
                    }, {
                        name: 'phone',
                        label: '手机号',
                        align: 'center',
                        rule: 'required,mobile'
                    }, {
                        name: 'emali',
                        label: '邮箱',
                        align: 'center',
                        rule: 'email'
                    }, {
                        name: 'salemanName',
                        label: '投资顾问',
                        align: 'center',
                        type: 'findgrid',
                        rule: 'chinese',
                        attrs: {
                            'data-options': {
                                include: 'salemanName:name,salemanPhone:phone',
                                dialogOptions: {
                                    title: '查找投资顾问',
                                    width: 600,
                                    height: 400
                                },
                                gridOptions: {
                                    width: '100%',
                                    height: '100%',
                                    fullGrid: true,
                                    showLinenumber:false,
                                    columnMenu: false,
                                    local: 'local',
                                    dataUrl: '/admin/salesman/investaadviser/selInvestaAdvisers',
                                    columns: [
                                        {name: 'name', label: '姓名', width : 100, finalWidth: true},
                                        {name: 'phone', label: '手机', width : 100, finalWidth: true},
                                        {name: 'remarks', label: '备注', width : 100, finalWidth: true}
                                    ]
                                }
                            }
                        },
                        render: function (value) {
                            return value;
                        }
                    }, {
                        name: 'salemanPhone',
                        label: '投资顾问手机',
                        align: 'center',
                        rule: 'mobile'
                    }, {
                        name: 'status',
                        label: '用户状态',
                        align: 'center',
                        rule: 'required',
                        type: 'select',
                        items: [{0: '正常'}, {1: '注销'}, {2: '禁用'}],
                        render: $.datagrid.renderItem
                    }, {
                        name: 'bindCard',
                        label: '是否已绑卡',
                        align: 'center',
                        rule: 'required',
                        type: 'boolean',
                        render: function (value) {
                            return (value && String(value) === 'true') ? '<span style="color:green;">是</span>' : '<span style="color:red;">否</span>'
                        }
                    }, {
                        name: 'openAccount',
                        label: '是否已认证/开户',
                        align: 'center',
                        rule: 'required',
                        type: 'boolean',
                        render: function (value) {
                            return (value && String(value) === 'true') ? '<span style="color:green;">是</span>' : '<span style="color:red;">否</span>'
                        }
                    }, {
                        name: 'registerDate',
                        label: '注册时间',
                        align: 'center',
                        pattern: 'yyyy-MM-dd HH:mm:ss:000',
                        render: function (value) {
                            return value ? value.substr(0, 19) : value
                        },
                        type: 'date',
                        edit: false,
                        rule: 'required'
                    }, {
                        name: 'lastLoginDate',
                        label: '最后登录',
                        align: 'center',
                        pattern: 'yyyy-MM-dd HH:mm:ss:000',
                        render: function (value) {
                            return value ? value.substr(0, 19) : value
                        },
                        type: 'date',
                        edit: false,
                        rule: 'required'
                    }
                ],
                linenumberAll: true,
                delUrl: '/admin/user/del',
                editUrl: '/admin/user/edit',
                paging: {pageSize: 20, pageIndex: 1},
                importOption: {
                    type: 'dialog',
                    options: {url: '/admin/user/importUser', width: 500, height: 300, title: '导入用户信息'}
                }
            });
        });


        function userListExport() {
            var dates = $(user_table).data('selectedDatas');
            if (dates && dates.length !== 0) {
                var ids = [];
                dates.forEach(function (e) {
                    ids.push(e.id);
                });
                BJUI.ajax('ajaxdownload', {
                    url: '/admin/user/export',
                    data: {ids: ids.join(",")}
                });
            } else
                BJUI.alertmsg('info', BJUI.getRegional('datagrid.selectMsg'))
        }


        function userListShowUser(value, data) {
            return '<a href="javascript:;" onclick="userListOpenDialog(\'' + data.id + "','" + data.userName + '\')">' + data.userName + '</a>';
        }

        function userListOpenDialog(id, userName) {
            BJUI.dialog({
                id: 'userInfo_' + id,
                url: '/admin/user/userInfo?id=' + id,
                title: '' + userName + '用户信息',
                width: 1200,
                height: 1200 * 0.618
            });
        }
    </script>
</div>
